package cn.itzzx.context;

import cn.itzzx.beans.factory.BeanFactory;

import javax.servlet.ServletContext;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * TODO 写点注视啦
 *
 * @author Martin
 * @date 2020-05-03
 * @see 1.0
 */
public class ContextLoader {

    private BeanFactory beanFactory = new BeanFactory();


    /**
     * 根据 scan.properties 配置文件的包名 扫描包路径下的类
     */
    public void initWebApplicationContext() {
        Properties prop = new Properties();
        InputStream resourceAsStream = ContextLoader.class.getClassLoader().getResourceAsStream("scan.properties");
        try {
            prop.load(resourceAsStream);
            //获取需要扫描的包
            String scanPackage = prop.getProperty("scanPackage");
            beanFactory.refresh(scanPackage);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

}
